﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HomeFramework.Client.Utilities;

namespace HomeFramework.Client.Forms
{
    public partial class TrayForm : Form
    {
        public TrayForm()
        {
            InitializeComponent();
        }

        private void TrayForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            if (e.CloseReason == CloseReason.FormOwnerClosing || e.CloseReason == CloseReason.UserClosing) e.Cancel = true;
            else
            {
                tray.Visible = false;
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HFUtils.SaveStatus();
            Application.Exit();
        }

        private void openHomeFrameworkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Show();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            pathAdder.ShowDialog();
            if (!string.IsNullOrEmpty(pathAdder.SelectedPath) && !HFUtils.MonitoredPaths.Contains(pathAdder.SelectedPath))
            {
                HFUtils.MonitoredPaths.Add(pathAdder.SelectedPath);
                RebindPaths();
            }
        }

        private void RebindPaths()
        {
            paths.Items.Clear();
            paths.Items.AddRange(HFUtils.MonitoredPaths.ToArray());
        }

        private void TrayForm_Load(object sender, EventArgs e)
        {
            RebindPaths();
        }
    }
}
